@extends('admin.header')
@section('title','添加专家界面')
@section('content')
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
            <script type="text/javascript" src="/assets/js/ueditor/ueditor.config.js"></script>
            <!-- 编辑器源码文件 -->
            <script type="text/javascript" src="/assets/js/ueditor/ueditor.all.js"></script>
            <!-- 语言包文件(建议手动加载语言包，避免在ie下，因为加载语言失败导致编辑器加载失败) -->
            <script type="text/javascript" src="/assets/js/ueditor/lang/zh-cn/zh-cn.js"></script>
            <script src="/assets/js/jquery.ajaxfileupload.js"></script>
            <script src="/assets/js/video.js"></script>
            <!-- date -->
            <script src="/assets/js/bootstrap-datetimepicker.min.js" type="text/javascript"></script>
            <script src="/assets/js/bootstrap-datetimepicker.zh-CN.js" type="text/javascript"></script>
            <div class="col-md-12" id="content">

                <div class="app_content_div" id="app_content_div_301Index">
                    <h3>修改专家</h3>
                </div>

                <form class="form-horizontal" action="/expert/update-list/{{$expert->id}}" method="post" enctype="multipart/form-data">
                    @csrf
                    <div class="form-group">
                        <label for="name" class="col-sm-2 control-label"><span style="color:#ff0000;">*</span>姓名</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="name" name="name" value="{{$expert->name}}">
                        </div></div>
                    @error('name')
                    <div class="alert alert-danger">{{$message}} </div>
                    @enderror

                    <div class="form-group">
                        <label for="sex" class="col-sm-2 control-label"><span style="color:#ff0000;">*</span>性别</label>

                        @if($expert->sex == "男")
                        <div class="col-sm-10">
                            <label class="radio-inline">
                                <input type="radio" name="sex" id="male" value="男" checked> 男
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="sex" id="female" value="女"> 女
                            </label>
                        </div>

                        @else
                            <div class="col-sm-10">
                                <label class="radio-inline">
                                    <input type="radio" name="sex" id="male" value="男" > 男
                                </label>
                                <label class="radio-inline">
                                    <input type="radio" name="sex" id="female" value="女" checked> 女
                                </label>
                            </div>
                        @endif

                    </div>
                    <div class="form-group">
                        <label for="upload_file" class="col-sm-2 control-label"><span style="color:red;">*</span>照片</label>
                        <div class="col-sm-10">
                            <input type="file" name="photo" id="photo" />
                            <img style="width:150px;height:130px;" src="{{$expert->photo}}" id="photo1" />
                        </div> </div>
                    @error('photo')
                    <div class="alert alert-danger">{{$message}} </div>
                    @enderror

                    <div class="form-group">
                        <label for="department" class="col-sm-2 control-label"><span style="color:red;">*</span>科室</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="department" name="department" value="{{$expert->department}}">
                        </div></div>
                    @error('department')
                    <div class="alert alert-danger">{{$message}} </div>
                    @enderror


                    <div class="form-group">
                        <label for="postion" class="col-sm-2 control-label"><span style="color:red;">*</span>职位</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="position" name="position" value="{{$expert->position}}" >
                        </div></div>
                    @error('position')
                    <div class="alert alert-danger">{{$message}} </div>
                    @enderror

                    <div class="form-group">
                        <label for="hospital" class="col-sm-2 control-label"><span style="color:red;">*</span>医院</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="hospital" name="hospital" value="{{$expert->hospital}}" >
                        </div></div>
                    @error('hospital')
                    <div class="alert alert-danger">{{$message}} </div>
                    @enderror

                    <div class="form-group" >
                        <label for="description" class="col-sm-2 control-label"><span style="color:red;">*</span>简介</label>
                        <div class="col-sm-10">
                            <script id="introduction" name="introduction" type="text/plain">{!! $expert->introduction !!}</script>
                            <script type="text/javascript">
                                var editor = UE.getEditor('introduction')
                            </script>
                        </div>
                    </div>
                    @error('introduction')
                    <div class="alert alert-danger">{{$message}} </div>
                    @enderror

                    <div class="form-group" >
                        <label for="description" class="col-sm-2 control-label"><span style="color:red;">*</span>简介</label>
                        <div class="col-sm-10">
                            <script id="degree" name="degree" type="text/plain">{!! $expert->degree !!}</script>
                            <script type="text/javascript">
                                var editor = UE.getEditor('degree')
                            </script>
                        </div>
                    </div>
                    @error('degree')
                    <div class="alert alert-danger">{{$message}} </div>
                    @enderror

                    <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-10">
                            <button type="submit" class="btn btn-default">确定</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
</body>
<script language="javascript">
    $(function(){

        $("#photo").on("change", function(){
            var file = this.files[0];//获取上传的图片
            if(this.files && file){//图片存在，且已被获取
                // 检查文件类型
                var fileType = file.type;//获取文件类型
                if(fileType !== 'image/gif' && fileType !== 'image/png' && fileType !== 'image/jpeg'){
                    alert("请选择 GIF、PNG 或 JPEG 格式的图片文件。");
                    $("#photo").val("");//将id为photo的标签读取的文件清除
                    return;

                }

                // 检查文件大小
                var fileSize = file.size;//获取文件大小
                if(fileSize > 2000000){
                    alert("图片文件大小不能超过 2MB。");
                    $("#photo").val("");
                    return;
                }

                var reader = new FileReader();//文件读取器
                reader.readAsDataURL(file); //设置成file的URL地址，便于在界面上显示图片缩略图
                reader.onload = function(e){//触发onload处理事件
                    $("#photo1").attr("src", e.target.result);//将photo的src设置为目标文件的地址
                    //attr()函数将 photo1的src属性改为文件的数据，用于在界面预览显示

                    alert("文件上传成功！");
                }
            }
        });
    });
</script>

</html>
@endsection
